/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportcenter.support.resourceload;

import org.jdom.*;
import org.jdom.input.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.*;

public class DataSourceConfig {

    private static final String CONFIG_FILENAME = "xml/datasource.xml";
    private String dbDriverName = null;
    private String dbUser = null;
    private String dbPassword = null;
    private String dbURI = null;
    private int dbPoolMinSize = 0;
    private int dbPoolMaxSize = 0;
    private static final Log LOG =
            LogFactory.getLog(DataSourceConfig.class);

    public DataSourceConfig(String sgbd) {
        SAXBuilder builder = new SAXBuilder();

        try {

            InputStream is =
                    this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILENAME);

            Document doc = builder.build(is);
            Element root = doc.getRootElement();

            dbDriverName = root.getChild(sgbd).getChild("dbDriverName").getTextTrim();
            dbUser = root.getChild(sgbd).getChild("dbUser").getTextTrim();
            dbPassword = root.getChild(sgbd).getChild("dbPassword").getTextTrim();
            dbURI = root.getChild(sgbd).getChild("dbURI").getTextTrim();
            dbPoolMinSize =
                    Integer.parseInt(root.getChild(sgbd).getChild("dbPoolMinSize").getTextTrim());
            dbPoolMaxSize =
                    Integer.parseInt(root.getChild(sgbd).getChild("dbPoolMaxSize").getTextTrim());

        } catch (Exception ex) {
            LOG.error("Could not read configuration file: ", ex);
        }

    }

    public String getDbDriverName() {
        return dbDriverName;
    }

    public String getDbUser() {
        return dbUser;
    }

    public String getDbPassword() {
        return dbPassword;
    }

    public String getDbURI() {
        return dbURI;
    }

    public int getDbPoolMinSize() {
        return dbPoolMinSize;
    }

    public int getDbPoolMaxSize() {
        return dbPoolMaxSize;
    }
}
